package com.clement.spring.study.controller;

import com.clement.spring.study.model.Person;
import com.clement.spring.study.model.PersonForm;
import com.clement.spring.study.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.Validator;

/**
 * Created by Clement on 2017/3/2.
 */
@RestController
public class ExperimentController {

    @Autowired
    Person person;


    @Autowired
    Validator validator;


    @Autowired
    @GetMapping(value = "joda/date" )
    public Person getPerson(){
        return person;
    }

    /**
     * this is to test the @valid working
     * @param person
     */
    @PostMapping(value = "person")
    public void getPersonFromRequest( @Valid @RequestBody PersonForm person) {
        System.out.println(person.toString());
    }

    @PostMapping(value = "user/form/", consumes = "application/*")
    public User getUserFormPostRequest(@RequestBody User user) {
        return user;
    }
}
